<template>
	<view>
		<u-navbar bgColor="transparent" placeholder autoBack leftIconColor="#fff">
			<view class="u-nav-slot ftwt" slot="left">
				<view class="c-fff ftwt fts16">贵阳市移动源排污监控平台</view>
			</view>
			<view class="u-nav-slot ftwt" slot="right">
				<u-icon name="setting" color="#fff" size="20" @click="goTologinSet"></u-icon>
			</view>
		</u-navbar>
		<view class="content">
			<u-swiper
				:list="list2"
				keyName="image"
				height="160"
				radius="8"
				showTitle
				indicator
				indicatorMode="line"
				circular
			></u-swiper>
			
			<view class="grid-container">
				<view class="grid-item" v-for="(item,index) in baseList" :key="index" @click="clickGird(item,index)">
					<image class="mab5" :src="item.url" mode="" style="width: 72px;height: 72px;"></image>
					<text class="grid-text">{{item.title}}</text>
				</view>
			</view>

		</view>
		

	</view>

</template>

<script>
	export default {
		data() {
			return {
				requestUrl:'http://'+uni.getStorageSync("IPNumber")+':'+uni.getStorageSync("portNumber") +'/vepts/api/v1/guiyang',
				list2: [{
						image: '/static/banner/banner1.png',
						title: '最新政策解读',
				}],
				
				baseList: [
					{
						url: '/static/icon/ic_jcjl.png',
						title: '检测记录'
					},
					{
						url: '/static/icon/ic_hmd.png',
						title: '黑名单'
					},
					
				],
				
				isVerify:false, // 是否验证
				
			}
		},
		onReady() {
			
		},
		onShow(e) {
			if(!this.isVerify){
				this.loginVerify(uni.getStorageSync('accessToken'))
			}
		},
		onLoad(param) {
			console.log(param);
			if(param&&param.accessToken){ // 贵阳生态云传参跳转进入
				uni.setStorageSync('accessToken',param.accessToken)
				this.isVerify=true
				this.loginVerify(uni.getStorageSync('accessToken'),'生态云')
			}
		},
		methods: {
			loginVerify(accessToken,type){
				this.requestUrl='http://'+uni.getStorageSync("IPNumber")+':'+uni.getStorageSync("portNumber") +'/vepts/api/v1/guiyang'
				if(!accessToken){ // 无token
					uni.reLaunch({
						url: '/pages/login/login'
					})
					return	
				}
				if(!this.isValidUrl(this.requestUrl)){ // 请求路径不对
					this.$all.toast('请先配置登录配置')
					setTimeout(()=>{
						this.goTologinSet() // 跳转登录配置
					},800)
					return
				}
				let params = {
					accesstoken: accessToken,
				}
				this.$ajax.myRequest({
					url: this.requestUrl + '/yhdlloginSTY',
					data: params,
					method: 'POST',
					success: (res) => {
						console.log(res);
						this.isVerify=false
						if (res.data.code == 200) {
							// this.$all.toast(res.data.msg)
							if(type=='生态云' && !uni.getStorageSync('tsno')){ // 来自贵州生态云且未配置登录配置
								this.goTologinSet() // 跳转登录配置
							}
						}else{
							this.$all.toast(res.data.msg)
							setTimeout(()=>{
								uni.clearStorageSync('accessToken') // 清除缓存的token
								uni.reLaunch({
									url: '/pages/login/login'
								})
							},800)
						}
					},
				})
			},
			isValidUrl(url) {
			  const regex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(\:[0-9]+)?)(\/[a-zA-Z0-9%_.~+-]+)*\/?(\?[a-zA-Z0-9%_.,~+-=&]*)?(#[a-zA-Z0-9_-]+)?$/;
			  return regex.test(url);
			},
			
			clickGird(item,index) { // 点击菜单
				if(index == 1) {
					uni.navigateTo({
						url: '/pages/blackList/index'
					})
				} else if(index == 0) {
					uni.navigateTo({
						url: '/pages/inspectionRecord/index'
					})
				}
			},
			
			goTologinSet(){
				uni.navigateTo({
					url: '/pages/login/loginSet'
				})
			},
			
		}
	}
</script>

<style lang="scss">
	page{
		background-image: url('@/static/backImage/back1.png');
		background-color: #fff;
		padding: 10px 20px;
	}
	.content {
		.grid-container {
		  display: grid;
		  grid-template-columns: repeat(2, 1fr); /* 3等分列 */
			grid-gap:0;
			margin-top: 20px;
			border-radius: 8px;
			background-color: #fff;
			padding: 10px 0;
		}
		 
		.grid-item {
		  // grid-column: 1 / 2; /* 占据第一列 */
			// height: 25vw;
			display: flex;
			flex-flow: column;
			justify-content: center;
			align-items: center;
			.grid-text{
				font-size: 14px;
				color: #666;
				font-weight: 600;
			}
		}
		
		
	}

	
</style>
